<template>
    <div>
        <el-form ref="form" :model="obj.data" label-width="80px">
            <el-form-item label="故障图片">
                <div class="img" v-html="proxy.$utils.showImgs(proxy, obj.data.imgs, 'fault')"></div>
            </el-form-item>
            <el-form-item label="故障描述">
                <div>{{obj.data.msg}}</div>
            </el-form-item>
            <el-form-item label="维修人" prop="faultuserid" :rules="[formRulesMixin.notNull]" v-if="obj.show">
                <el-select v-model="obj.data.faultuserid" placeholder="选择维修人">
                    <el-option v-for="(item,index) in obj.property_all" :key="index" :label="item.name" :value="item.property_id" />
                </el-select>
            </el-form-item>
            <el-form-item v-if="obj.show" class="dialog-btns-item">
                <div class="dialog-btns">
                    <span class="btn clear" @click="$emit('close')">取消</span>
                    <span class="btn sub ml10" @click.prevent="upData">提交</span>
                </div>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
    import { reactive,ref,getCurrentInstance,toRaw,inject } from 'vue'
    let { proxy } = getCurrentInstance()
    let obj = reactive({
        data:{
            fault_id: inject("id").value || 0,
            imgs: "",
            msg: "",
            faultuserid:"",
            faulttime:""
        },
        show:true
    })

    let init = async () => {
        obj.property_all = await proxy.$utils.getProperty(proxy, 4)
        proxy.$ajax({
            url: 'fault/get',
            data: obj.data,
            bfLoading: true
        }).then(d => {
            if(d.success){
                obj.data = {...obj.data, ...d.msg}
                obj.show = obj.data.faultuserid==''
                // console.log(obj.data)
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
    init()
    let upData = () => {
        proxy.$refs['form'].validate(valid => {
            if (valid) {
                proxy.$ajax({
                    url: 'fault/design',
                    data: obj.data,
                    bfLoading: true,
                }).then(d => {
                    if(d.success){
                        proxy.elMessageMixin(`指定维修人成功`, 'success')
                        proxy.$emit('init')
                        proxy.$emit('close')
                    }else{
                        proxy.elMessageMixin(d.err, 'error')
                    }
                }).catch(() => { })
            }else{
                return false
            }
        })
    }
</script>

<style scoped>
    /* ::-webkit-scrollbar { width:10px; background-color: #CCCCCC; } */
    .img { display: flex; justify-content: center; align-items: flex-start; flex-wrap: wrap; }
    :deep(.img img) { max-width: 300px; }
</style>